var a = require("../../requests/request.js"), t = getApp();

Page({
    data: {
        Hotcarserial: [],
        pageindex: 1,
        allcount: 0,
        carlistdata: [],
        suggesthidden: !0,
        hotcarserialhidden: !1,
        calisthidden: !0,
        nodatahidden: !0,
        loadinghidden: !0,
        clearhidden: !0,
        searchclass: "btn-search btn-search-none",
        searchtext: "",
        beginsuggest: !1,
        isfocus: !1
    },
    onLoad: function(t) {
        var e = this;
        console.log(t.searchtxt), t.searchtxt && e.setData({
            searchtext: t.searchtxt
        }), "" === e.data.searchtext || void 0 == e.data.searchtext ? (e.setData({
            suggesthidden: e.data.suggesthidden,
            hotcarserialhidden: e.data.hotcarserialhidden,
            isfocus: !0
        }), a.getHotcarserial(function(a) {
            e.data.Hotcarserial = a.Table, console.log(e.data.Hotcarserial), e.setData({
                Hotcarserial: e.data.Hotcarserial
            });
        }, function(a) {
            console.log(a);
        }, function(a) {
            console.log(a);
        })) : e.bindSearch();
    },
    lower: function(t) {
        console.log(t);
        var e = this;
        "" !== this.data.searchtext && (console.log(e.data.allcount), 20 * e.data.pageindex < e.data.allcount && (e.data.pageindex += 1, 
        e.setData({
            loadinghidden: !1,
            nodatahidden: !0,
            suggesthidden: !0,
            hotcarserialhidden: !0
        }), a.getSouCar(this.data.searchtext, e.data.pageindex, 20, function(a) {
            if (void 0 != a.Data.carlist && 0 !== a.Data.carlist.length) {
                for (var t = 0; t < a.Data.carlist.length; t++) e.data.carlistdata.push(a.Data.carlist[t]);
                e.setData({
                    carlistdata: e.data.carlistdata,
                    calisthidden: !1,
                    loadinghidden: !0,
                    nodatahidden: e.data.nodatahidden
                });
            }
        }, function(a) {
            console.log(a);
        }, function(a) {
            console.log(a);
        })));
    },
    bindClear: function() {
        var a = this;
        a.setData({
            loadinghidden: !0,
            nodatahidden: !0,
            suggesthidden: !0,
            hotcarserialhidden: !1,
            searchtext: "",
            calisthidden: !0,
            clearhidden: !0,
            searchclass: "btn-search btn-search-none",
            Hotcarserial: a.data.Hotcarserial
        });
    },
    bindSearch: function() {
        var t = this;
        "" !== this.data.searchtext && (t.setData({
            loadinghidden: !1,
            nodatahidden: !0,
            suggesthidden: !0,
            hotcarserialhidden: !0
        }), this.data.pageindex = 1, a.getSouCar(this.data.searchtext, this.data.pageindex, 20, function(a) {
            console.log(a.Data.carlist), t.data.allcount = a.Data.allcount, void 0 == a.Data.carlist || 0 === a.Data.carlist.length ? (t.data.nodatahidden = !1, 
            t.setData({
                winHeight: 0
            })) : wx.getSystemInfo({
                success: function(a) {
                    t.setData({
                        winHeight: a.windowHeight - 45
                    });
                }
            }), t.data.carlistdata = a.Data.carlist, t.setData({
                carlistdata: a.Data.carlist,
                calisthidden: !1,
                loadinghidden: !0,
                nodatahidden: t.data.nodatahidden
            });
        }, function(a) {
            console.log(a);
        }, function(a) {
            console.log(a);
        }));
    },
    bindSearchInput: function(t) {
        var e = this;
        e.setData({
            nodatahidden: !0,
            suggestdata: []
        }), this.data.searchtext = t.detail.value, "" === this.data.searchtext ? (e.data.clearhidden = !0, 
        e.data.searchclass = "btn-search btn-search-none", e.data.hotcarserialhidden = !1) : (e.data.clearhidden = !1, 
        e.data.hotcarserialhidden = !0, e.data.searchclass = "btn-search"), console.log(this.data.searchtext), 
        e.setData({
            suggesthidden: !1,
            hotcarserialhidden: e.data.hotcarserialhidden,
            loadinghidden: !0,
            calisthidden: !0,
            searchclass: e.data.searchclass,
            clearhidden: e.data.clearhidden
        }), a.getSuggest(this.data.searchtext, function(a) {
            e.setData({
                suggestdata: a.Data.suglist
            });
        }, function(a) {
            console.log(a);
        }, function(a) {
            console.log(a);
        });
    },
    toCar: function(a) {
        console.log(a.currentTarget.dataset.id), wx.navigateTo({
            url: "../summary/summary?id=" + a.currentTarget.dataset.id + "&name=" + a.currentTarget.dataset.name
        });
    },
    returnBtn: function() {
        t.gotoIndex();
    }
});